TOP

SQL FULL OUTER JOIN Keyword

YouLibreCalc for Excel logo

SQL FULL OUTER JOIN Description

The keyword FULL OUTER JOIN returns all records if there is a match in the left (table1) or right (table2) records of the table.


The instructions FULL OUTER JOIN and FULL JOIN are the same.

FULL OUTER JOIN Syntax

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition

SQL FULL JOIN

Demonstration database

In this tutorial we will use the famous example database "Northwind".

Below is a sample from the table "Customers" ("Customers"):

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.5021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.5023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

And the sample from the table "Orders" ("Orders"):

ProductIDOrderIDCustomerIDEmployeeIDOrderDateShipperID
1102489051996-07-043
2102498161996-07-051
3102503441996-07-082
4102518431996-07-081
5102527641996-07-092

SQL FULL OUTER JOIN Example

The following SQL statement selects all customers and all orders:

Run SQLSELECT Customers.CustomerName, Orders.OrderID 
FROM Customers 
FULL OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID 
ORDER BY Customers.CustomerName

A sample from the result set might look like this:

CustomerName OrderID
Null 10309
Null 10310
Alfreds Futterkiste Null
Ana Trujillo Emparedados y helados 10308
Antonio Moreno Taquería Null
The keyword FULL OUTER JOIN returns all matching records from both tables regardless of whether the other table matches or not. So if there are rows in "Customers" ("Customers") that have no matches in "Orders" ("Orders"), or if there are rows in "Orders" that have no matches in "Customers", those rows are also will be listed.